/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 逆袭人生
 * Date: 2024-08-21
 * Time: 10:04
 */
public class method {
//    public static 返回值类型 方法名(形式参数列表) {
//              方法体;
//    }
    //实现一个两个整数相加的方法
    //形参
    public static int sum(int a,int b) {
        return (a + b);
    }
    //实现一个函数，检测一个年份是否是闰年
    public static boolean isLeapYear(int year) {
        if ((0 == year % 4 && 0 != year % 100) || 0 == year % 400) {
            return true;
        }else {
            return false;
        }
    }
    public static void main1(String[] args) {
        int x = 10;
        int y = 20;
        int ret = sum(x,y);//实参
        System.out.println(ret);
    }

    //求n的阶乘
    public static  int fac(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }
    //求k的阶乘的和
    public static int facSum(int k) {
        int sum = 0;
        for (int i = 1; i <= k; i++) {
            sum += fac(i);
        }
        return sum;
    }
    public static void main2(String[] args) {
        System.out.println(facSum(5));
    }

    public static void swap(int x,int y) {
        int tmp = x;
        x = y;
        y = tmp;

    }
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前：" + a + " " + b);

        swap(a,b);

        System.out.println("交换后-：" + a + " " + b);
        //事实上只交换了x和y
    }

}
